# 示例1
# 输入
# Life is painting a  picture, not doing 'a sum'  (a和picture之间有两个空格)
#
# 8 15,20 26,43 45
# 输出:
# Life is painting a picture, not doing 'a sum'
#
# [8,15][19,25][42, 44]
# 说明:
# a和picture中间多余的空格进行删除
s = input()
list_1 = [i.split(" ") for i in input().split(",")]
# print(list_1)
tmp = []  # 用一个数组存关键单词
tmp1 = []
# print(s.find("p", 10))

# 提取关键字
for i in list_1:
    # print(s[int(i[0]):int(i[1]) + 1])
    tmp.append(s[int(i[0]):int(i[1]) + 1])

# 将双引号的子提取
while s.find("'") > 0:
    left = s.find("'")
    # print(left)
    right = left + 1
    while True:
        if s[right] == "'":
            tmp1.append(s[left:right + 1])
            s = s[:left] + "_" + s[right + 1:]
            # print(s)
            break
        else:
            right += 1
# print(tmp)
# print(s.split(" "))
# 去除空格
s1 = s.split(" ")
s2 = ''
for i in s1:
    if i not in '':
        s2 = s2 + i + " "
# print(s2)
# 拼接
i = 0
while s2.find("_") > 0:
    left1 = s2.find("_")
    s2 = s2[0:left1] + tmp1[i] + s[left1 + 1:-1]  # 为什么加2，因为40行多了个空格
    # print(s2)
    i += 1
# print(s2)
# 获取关键字的新下表
res = []
index = 0  # 防止重复的关键子取相同下标
for i in tmp:
    left = s2.find(i, index)
    res.append([left, left + len(i) - 1])
    index = s2.find(i) + len(i)
print(res)
